package com.kgc.ljp;

import com.kgc.ljp.dao.impl.NewsDaoImpl;
import com.kgc.ljp.entity.News;

import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.ForkJoinPool;

public class Text {
    public static void main(String[] args) {
        NewsDaoImpl ndi = new NewsDaoImpl();
        List<News> newsList = null;
        Scanner scan = new Scanner(System.in);
        int id = 0;
        News news = null;
        do {
            System.out.println("1.查询\n2.按id查询\n3.修改\n4.删除\n5.增加\n6.分页查询\n7.过滤查询");
            String choose = scan.next();
            switch (choose){
                case "1":
                    newsList = ndi.getList();
                    for (News newes:newsList){
                        newes.show();
                    }
                    break;
                case "2":
                    System.out.print("请输入id:");
                    id = scan.nextInt();
                    newsList = ndi.getListById(id);
                    if (newsList.size()!=0){
                        for (News newes:newsList){
                            newes.show();
                        }
                    }else{
                        System.out.println("此id不存在");
                    }
                    break;
                case "3":
                    System.out.print("请输入要修改的id:");
                    id = scan.nextInt();
                    news = new News(id,2,"233","233","233","233","233",new Date(),new Date());
                    if (ndi.updateNews(news)){
                        System.out.println("修改成功");
                    }else{
                        System.out.println("修改失败");
                    }
                    break;
                case "4":
                    System.out.print("请输入id:");
                    id = scan.nextInt();
                    if (ndi.deleteNews(id)){
                        System.out.println("删除成功");
                    }else{
                        System.out.println("此id信息不存在");
                    }
                    break;
                case "5":
                    news = new News(2,"333","333","333","333","333",new Date(),new Date());
                    if (ndi.addNews(news)){
                        System.out.println("添加成功");
                    }else{
                        System.out.println("添加失败");
                    }
                    break;
                case "6":
                    System.out.print("请输入显示条数:");
                    int pageSize = scan.nextInt();
                    System.out.print("请输入显示条数:");
                    int currPage = scan.nextInt();
                    newsList = ndi.getListByLimit(pageSize,currPage);
                    for (News newes:newsList){
                        newes.show();
                    }
                    break;
                case "7":
                    System.out.print("请输入查询的类型id(不输入按0):");
                    id = scan.nextInt();
                    System.out.print("请输入查询的标题(不输入按0):");
                    String title = scan.next();
                    if ((newsList = ndi.selectByInfo(id,title)).size()!=0){
                        for (News newes:newsList){
                            newes.show();
                        }
                    }else{
                        System.out.println("未查询到");
                    }
                    break;
            }
        }while (true);
    }
}
